<template>
    <div class="hot">
        <h4>今日热点</h4>
        <ul>
            <li v-for="(item) in arr">
                <router-link to="/detail">
                    <div class="left">
                        <i><img src="../assets/img/播放_play.png"></i>
                        <img :src="item.cover">
                    </div>
                    <div class="right">
                        <h5>《{{ item.title }}》</h5>
                        <div class="ping">
                            <van-rate v-model="value" allow-half size="10px" void-icon="star" void-color="#eee" />
                        </div>
                        <div class="a">
                            <span class="a">作者：</span>
                            <span class="aa">{{ item.author }}</span>
                        </div>
                        <i><img src="../assets/img/耳机声音_headphone-sound.png" alt=""></i>
                        <span class="aaa">{{ item.recordTime | tenThousand }}万</span>
                        
                           
                        
                    </div>
                    
                </router-link>
            </li>
        </ul>
    </div>
</template>
<script>
import { hot } from '../api/index'

export default {
    data() {
        return {
            arr: [],
            value: 3.5,
        }
    },

    filters: {
        tenThousand(value) {
            // 保留两位小数
            return ((value - 0) / 1000000000).toFixed(2);
        }
    },

    methods: {
        async getHot() {
            await hot()
                .then(
                    content => {
                        // console.log("---->", content);
                        let list = content.data.list;
                        let msg = content.msg;
                        if (msg === "成功") {
                            list.map(item => {
                                let obj = {};
                                obj.title = item.title;
                                obj.cover = item.cover;
                                obj.record = item.recordTime;
                                obj.author = item.author;
                                return obj;
                            })
                            this.arr = list;

                            localStorage.setItem("listen_book_hotbook",JSON.stringify(list));
                        }
                    }
                )
                .catch(
                    err => {
                        console.log("请求失败，请刷新", err);
                    }
                )
        }
    },

    created() {
        this.getHot();
    }
}
</script>
<style lang="less" scoped>
@import '../assets/css/varible.less';

.hot {
    margin-bottom: 80px;

    h4 {
        padding-left: 15px;
        font-weight: bold;
        font-size: 18px;
        color: @bgColor;
        margin-top: 20px;
        
    }

    ul {
       margin-top: -8px;
        li {
            padding-left: 5px;
            padding-top: 10px;

            a {
                display: flex;

                .left {
                    position: relative;
                    padding-left: 7px;
                    padding-top: 10px;
                    img {
                        width: 100px;
                        height: 100px;
                        border-radius: 5px;
                    }

                    i {
                        position: absolute;
                        top: 25px;
                        left: 30px;

                        img {
                            width: 50px;
                            height: 50px;

                        }
                    }
                }

                .right {
                    padding-left: 10px;
                    
                    div {

                        .a {
                            padding-top: 5px;
                            padding-left: 5px;
                            font-weight: lighter;
                            font-size: 15px;
                            color: black;

                        }
                    }

                    h5 {
                        font-size: 20px;
                        font-weight: bold;
                        font-family: a;
                        padding-top: 10px;
                        // padding-left: 5px;
                    }

                    .aa {
                        font-size: 15px;
                    }

                    i {
                        padding-left: 10px;

                        img {
                            width: 20px;
                            height: 20px;
                        }
                    }

                    .aaa {
                        
                        margin-left: 5px;
                        font-size: 15px;
                        font-weight: bold;
                        color: #ccc;
                    }
                    .ping{
                        padding-left: 15px;
                    }
                }
            }
        }
    }

}
</style>